home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_535 / setbatt / setbatt.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  7KB  |  281 lines

  1. /** DoRevision Header ** Header built automatically - do not edit! **********
  2.  *
  3.  *    (C) Copyright 1991 by Olaf Barthel
  4.  *
  5.  *    Name .....:    SetBatt.c
  6.  *    Created ..:    Wednesday 24-Jul-91 14:21
  7.  *    Revision .:    1
  8.  *
  9.  *    Date        Author        Comment
  10.  *    =========    ========    ====================
  11.  *    24-Jul-91    Olsen        Created this file!
  12.  *
  13.  ***************************************************************************/
  14.  
  15.     /* Argument template and extra help. */
  16.  
  17. #define ARG_TEMPLATE    "T=Timeout/K,U=UseLUNS/K,H=HostID/K/N,S=Sync/K"
  18.  
  19. #define ARG_HELP    "\nUsage: SetBatt [Timeout L|S] [UseLUNS Y|N] [HostID n] [Sync Y|N]\n\n\
  20.                Timeout Set (L)ong or (S)hort SCSI selection timeout.\n\
  21.                UseLUNS Access logical units above 0 at any given\n\
  22.                        SCSI address, responds to (Y)es or (N)o.\n\
  23.                HostID  Set the SCSI controller's host ID, correct IDs are 0..7.\n\
  24.                Sync    Initiate synchronous transfer, responds to\n\
  25.                        (Y)es or (N)o.\n\n"
  26.  
  27.     /* Argument vector offsets. */
  28.  
  29. enum    {    ARG_TIMEOUT,ARG_USELUNS,ARG_HOSTID,ARG_SYNC };
  30.  
  31.     /* Handy international toupper() macro. */
  32.  
  33. #define ToUpper(c)    ((((c) >= 224 && (c) <= 254) || ((c) >= 'a' && (c) <= 'z')) ? (c) - 32 : (c))
  34.  
  35.     /* Shared library identifiers. */
  36.  
  37. struct ExecBase        *SysBase;
  38. struct DosLibrary    *DOSBase;
  39.  
  40. struct Library        *BattMemBase;
  41.  
  42.     /* Prototypes for this module. */
  43.  
  44. LONG __saveds        Main(VOID);
  45. VOID            ShowConfig(VOID);
  46.  
  47.     /* Main():
  48.      *
  49.      *    Main entry point to this module.
  50.      */
  51.  
  52. LONG __saveds
  53. Main()
  54. {
  55.     LONG Result = RETURN_FAIL;
  56.  
  57.         /* Set up SysBase. */
  58.  
  59.     SysBase = *(struct ExecBase **)4;
  60.  
  61.         /* Open dos.library. */
  62.  
  63.     if(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",37))
  64.     {
  65.             /* Open battmem.resource. */
  66.  
  67.         if(BattMemBase = (struct Library *)OpenResource(BATTMEMNAME))
  68.         {
  69.             struct RDArgs    *ArgsPtr;
  70.             UBYTE        **Args;
  71.  
  72.                 /* Allocate space for the RDArgs auxilary structure. */
  73.  
  74.             if(ArgsPtr = AllocVec(sizeof(struct RDArgs),MEMF_PUBLIC|MEMF_CLEAR))
  75.             {
  76.                     /* Provide extended help information. */
  77.  
  78.                 ArgsPtr -> RDA_ExtHelp = ARG_HELP;
  79.  
  80.                     /* Allocate space for the arguments. */
  81.  
  82.                 if(Args = (UBYTE **)AllocVec(sizeof(UBYTE *) * 4,MEMF_PUBLIC|MEMF_CLEAR))
  83.                 {
  84.                         /* Read the args if any. */
  85.  
  86.                     if(ReadArgs(ARG_TEMPLATE,(APTR)Args,ArgsPtr))
  87.                     {
  88.                         UBYTE Data;
  89.  
  90.                         Result = RETURN_OK;
  91.  
  92.                             /* Obtain exclusive access
  93.                              * to battmem.resource.
  94.                              */
  95.  
  96.                         ObtainBattSemaphore();
  97.  
  98.                             /* Set the SCSI scan timeout. */
  99.  
  100.                         if(Args[ARG_TIMEOUT])
  101.                         {
  102.                             switch(ToUpper(Args[ARG_TIMEOUT][0]))
  103.                             {
  104.                                 case 'L':    Data = 1;
  105.                                         WriteBattMem(&Data,BATTMEM_SCSI_TIMEOUT_ADDR,BATTMEM_SCSI_TIMEOUT_LEN);
  106.                                         break;
  107.  
  108.                                 case 'S':    Data = 0;
  109.                                         WriteBattMem(&Data,BATTMEM_SCSI_TIMEOUT_ADDR,BATTMEM_SCSI_TIMEOUT_LEN);
  110.                                         break;
  111.  
  112.                                 default:    Printf("SetBatt: Argument not recognized \"%s\".\n",Args[ARG_TIMEOUT]);
  113.                                         Result = RETURN_FAIL;
  114.                                         break;
  115.                             }
  116.                         }
  117.  
  118.                             /* Toggle LUNs. */
  119.  
  120.                         if(Result != RETURN_FAIL)
  121.                         {
  122.                             if(Args[ARG_USELUNS])
  123.                             {
  124.                                 switch(ToUpper(Args[ARG_USELUNS][0]))
  125.                                 {
  126.                                     case 'Y':    Data = 1;
  127.                                             WriteBattMem(&Data,BATTMEM_SCSI_LUNS_ADDR,BATTMEM_SCSI_LUNS_LEN);
  128.                                             break;
  129.  
  130.                                     case 'N':    Data = 0;
  131.                                             WriteBattMem(&Data,BATTMEM_SCSI_LUNS_ADDR,BATTMEM_SCSI_LUNS_LEN);
  132.                                             break;
  133.  
  134.                                     default:    Printf("SetBatt: Argument not recognized \"%s\".\n",Args[ARG_USELUNS]);
  135.                                             Result = RETURN_FAIL;
  136.                                             break;
  137.                                 }
  138.                             }
  139.                         }
  140.  
  141.                             /* Select SCSI host ID. */
  142.  
  143.                         if(Result != RETURN_FAIL)
  144.                         {
  145.                             if(Args[ARG_HOSTID])
  146.                             {
  147.                                 LONG ID = *((LONG *)Args[ARG_HOSTID]);
  148.  
  149.                                 if(ID < 0 || ID > 7)
  150.                                 {
  151.                                     Printf("SetBatt: SCSI Host ID must be between 0 and 7.\n");
  152.                                     Result = RETURN_FAIL;
  153.                                 }
  154.                                 else
  155.                                 {
  156.                                     Data = ID ^ 7;
  157.                                     WriteBattMem(&Data,BATTMEM_SCSI_HOST_ID_ADDR,BATTMEM_SCSI_HOST_ID_LEN);
  158.                                 }
  159.                             }
  160.                         }
  161.  
  162.                             /* Toggle synchronous transfer. */
  163.  
  164.                         if(Result != RETURN_FAIL)
  165.                         {
  166.                             if(Args[ARG_SYNC])
  167.                             {
  168.                                 switch(ToUpper(Args[ARG_SYNC][0]))
  169.                                 {
  170.                                     case 'Y':    Data = 1;
  171.                                             WriteBattMem(&Data,BATTMEM_SCSI_SYNC_XFER_ADDR,BATTMEM_SCSI_LUNS_LEN);
  172.                                             break;
  173.  
  174.                                     case 'N':    Data = 1;
  175.                                             WriteBattMem(&Data,BATTMEM_SCSI_SYNC_XFER_ADDR,BATTMEM_SCSI_LUNS_LEN);
  176.                                             break;
  177.  
  178.                                     default:    Printf("SetBatt: Argument not recognized \"%s\".\n",Args[ARG_SYNC]);
  179.                                             Result = RETURN_FAIL;
  180.                                             break;
  181.                                 }
  182.                             }
  183.                         }
  184.  
  185.                             /* Show the current configuration. */
  186.  
  187.                         if(Result != RETURN_FAIL)
  188.                             ShowConfig();
  189.  
  190.                             /* Release access semaphore. */
  191.  
  192.                         ReleaseBattSemaphore();
  193.  
  194.                             /* Start the cleanup. */
  195.  
  196.                         FreeArgs(ArgsPtr);
  197.                     }
  198.                     else
  199.                         PrintFault(IoErr(),"SetBatt");
  200.  
  201.                     FreeVec(Args);
  202.                 }
  203.                 else
  204.                     Printf("SetBatt: Unable to allocate argument line!\n");
  205.  
  206.                 FreeVec(ArgsPtr);
  207.             }
  208.         }
  209.         else
  210.             Printf("SetBatt: Failed to open \"%s\"!\n",BATTMEMNAME);
  211.  
  212.         CloseLibrary(DOSBase);
  213.     }
  214.  
  215.     return(Result);
  216. }
  217.  
  218.     /* ShowConfig():
  219.      *
  220.      *    Display the current battmem settings.
  221.      */
  222.  
  223. VOID
  224. ShowConfig()
  225. {
  226.     UBYTE Data;
  227.  
  228.         /* Amnesia on the Amiga side? */
  229.  
  230.     if(!ReadBattMem(&Data,BATTMEM_AMIGA_AMNESIA_ADDR,BATTMEM_AMIGA_AMNESIA_LEN))
  231.     {
  232.         if(!(Data & 1))
  233.             Printf("\33[33mWarning\33[31m - a memory loss has occured on the Amiga side!\n\n");
  234.     }
  235.  
  236.         /* Long or short timeouts? */
  237.  
  238.     if(!ReadBattMem(&Data,BATTMEM_SCSI_TIMEOUT_ADDR,BATTMEM_SCSI_TIMEOUT_LEN))
  239.     {
  240.         if(Data & 1)
  241.             Printf("The SCSI selection timeout is \33[33mLONG\33[31m (2 seconds).\n");
  242.         else
  243.             Printf("The SCSI selection timeout is \33[33mSHORT\33[31m (128 miliseconds).\n");
  244.     }
  245.  
  246.         /* Scan LUNs? */
  247.  
  248.     if(!ReadBattMem(&Data,BATTMEM_SCSI_LUNS_ADDR,BATTMEM_SCSI_LUNS_LEN))
  249.     {
  250.         if(Data & 1)
  251.             Printf("Logical SCSI units above 0 \33[33mARE\33[31m accessed.\n");
  252.         else
  253.             Printf("Logical SCSI units above 0 \33[33mARE NOT\33[31m accessed.\n");
  254.     }
  255.  
  256.     Printf("\n");
  257.  
  258.         /* Amnesia on the shared Amiga/Amix side? */
  259.  
  260.     if(!ReadBattMem(&Data,BATTMEM_SHARED_AMNESIA_ADDR,BATTMEM_SHARED_AMNESIA_LEN))
  261.     {
  262.         if(!(Data & 1))
  263.             Printf("\33[33mWarning\33[31m - a memory loss has occured on the shared Amiga/Unix side!\n\n");
  264.     }
  265.  
  266.         /* Show SCSI host ID. */
  267.  
  268.     if(!ReadBattMem(&Data,BATTMEM_SCSI_HOST_ID_ADDR,BATTMEM_SCSI_HOST_ID_LEN))
  269.         Printf("The SCSI controller's host ID is \33[33m%ld\33[31m.\n",(Data & 7) ^ 7);
  270.  
  271.         /* Synchronous transfer enabled? */
  272.  
  273.     if(!ReadBattMem(&Data,BATTMEM_SCSI_SYNC_XFER_ADDR,BATTMEM_SCSI_SYNC_XFER_LEN))
  274.     {
  275.         if(!(Data & 1))
  276.             Printf("Synchronous transfer is \33[33mINITIATED\33[31m.\n");
  277.         else
  278.             Printf("Synchronous transfer is \33[33mNOT INITIATED\33[31m.\n");
  279.     }
  280. }
  281.